package com.yhao.stock.common.utils;

import java.math.BigDecimal;
import java.math.RoundingMode;

/**
 * @author: yhao
 * @time: 2021/2/6 14:14
 * @description:
 */
public class BigDecimalUtil {

    /**
     * @param unitPrice
     * @param oldPrice
     * @return
     * @desc 获取推荐值
     */
    public static Double getRecoRate(BigDecimal unitPrice, BigDecimal oldPrice) {

        return new BigDecimal(1).subtract(unitPrice.divide(oldPrice, 2, RoundingMode.HALF_UP)).multiply(new BigDecimal(10)).doubleValue();
    }


    /**
     * @param rent  租金
     * @param price 售价
     * @return
     * @desc 获取租售比
     */
    public static BigDecimal getZSRatio(int rent, int price) {
        BigDecimal rentBD = new BigDecimal(rent);
        BigDecimal priceBD = new BigDecimal(price);
        return rentBD.divide(priceBD, 4, RoundingMode.HALF_UP).divide(new BigDecimal(100), 4, RoundingMode.HALF_UP);
    }

    /**
     * @param x
     * @param y
     * @return
     * @desc 获取除数比率
     */
    public static BigDecimal getDivideData(int x, int y) {
        BigDecimal rentBD = new BigDecimal(x);
        BigDecimal priceBD = new BigDecimal(y);
        return rentBD.divide(priceBD, 3, RoundingMode.HALF_UP);
    }

}
